require 'osx/cocoa'
require 'macos/conversion_helpers'
require 'renderer'
include OSX

class CocoaRenderer < Renderer
  include ConversionHelpers
  
  def render_player(obj)
    poly = Polygon.new
    v = Vector.new(Point.new(obj.height, obj.width / 2))
    l = v.length
    a = v.angle
    
    poly.points << obj.position + Vector.new(obj.height / 2, obj.rotation).point
    poly.points << poly.points[0] - Vector.new(l, obj.rotation + a).point
    poly.points << poly.points[0] - Vector.new(l, obj.rotation - a).point
    
    NSColor.send("#{obj.color}Color").set
    path = NSBezierPath.alloc.init
    path.lineWidth = 2
    path.moveToPoint PointToNSPoint(poly.points[0])
    poly.points.each do |p|
      path.lineToPoint PointToNSPoint(p)
    end
    path.lineToPoint PointToNSPoint(poly.points[0])
    path.fill
  end
  
  def render_planet(obj)
    NSColor.send("#{obj.color}Color").set
    path = NSBezierPath.bezierPathWithOvalInRect(RectToNSRect(obj.rect))
    path.fill
  end
end